package ar.com.solidussource.howmuchmobile.activities.list;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;
import ar.com.solidussource.howmuchmobile.R;
import ar.com.solidussource.howmuchmobile.activities.generic.PaginatedListActivity;
import ar.com.solidussource.howmuchmobile.common.entities.Market;
import ar.com.solidussource.howmuchmobile.common.entities.Productprice;
import ar.com.solidussource.howmuchmobile.common.exception.ServiceException;
import ar.com.solidussource.howmuchmobile.services.mocks.ProductPriceMockService;

/**
 * Created with IntelliJ IDEA.
 * User: gustavo
 * Date: 11/20/12
 * Time: 11:25 AM
 * To change this template use File | Settings | File Templates.
 */
public class ProductpriceListActivity extends PaginatedListActivity<Productprice> {

    public ProductpriceListActivity() {
    }

    @Override
    public String getViewTitle() {
        return null;
    }

    @Override
    public void serviceCall() throws ServiceException {
        Market market = (Market) getIntent().getExtras().get("market");

        ProductPriceMockService productPriceMockService = new ProductPriceMockService();
        data.addAll(productPriceMockService.getProductprices(null, null));

    }

    @Override
    public BaseAdapter getListAdapter(Activity context) {
        return new ProductpriceArrayAdapter(context);
    }

    @Override
    public AdapterView.OnItemClickListener getListOnItemClickListener() {
        return null;
    }

    @Override
    public boolean isForContextMenu() {
        return false;
    }

    class ProductpriceArrayAdapter extends BaseAdapter {

        private Activity mContext;

        ProductpriceArrayAdapter(Activity context) {
            mContext = context;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = mContext.getLayoutInflater();
            View item = inflater.inflate(R.layout.list_productprice_row, null);

            TextView lblTitulo = (TextView)item.findViewById(R.id.name);
            lblTitulo.setText(data.get(position).getProduct().getName());

            TextView lblMoney = (TextView)item.findViewById(R.id.money);
            lblMoney.setText(Float.toString(data.get(position).getPrice()));

            TextView lblScore = (TextView)item.findViewById(R.id.score);
            lblScore.setText(Long.toString(data.get(position).getScore()));

            return(item);
        }

        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int i) {
            return data.get(i);
        }

        @Override
        public long getItemId(int i) {
            return data.get(i).getId();
        }
    }
}

